/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
 */

/**
 * Created by yfyang on 4/12/14.
 */
define([ 'adminapp', 'jquery-slimscroll', 'kindeditor', 'kindeditor-lang'], function ($app) {

    KindEditor.create('textarea#description', {
        themeType : 'simple',
        uploadJson: g.ctx + 'file/editor'
    });

    $app.navactive('brand');

    var prvview_tpl = Handlebars.compile($(g.preview_template).html());


    $app.uploader({'uploader': g.ctx + 'file/up?dpi=logo', 'buttonText': '点击上传LOGO', width: 140}, 'logoAttachmentUpload');
    $app.uploader({
        'uploader': g.ctx + 'file/up?dpi=env',
        'buttonText'     : '点击上传店铺图片', width: 140,
        queueSizeLimit   : 100,
        'onUploadSuccess': function (file, data, response) {
            var jsonData = eval('(' + data + ')');
            if (jsonData['status'] == 'OK') {
                var attachement_path = jsonData['data'];
                var $moPrictures = $('#mo_prictures');
                var val = $moPrictures.val();
                if (val) {
                    $moPrictures.val((val + ",") + attachement_path);
                } else {
                    $moPrictures.val(attachement_path);
                }

                $('#pricture-grid').append(prvview_tpl({ctx: g.ctx, data: attachement_path.replace('.', '.thumbnail.'), preview: attachement_path}))

            }
        }
    }, 'prictureAttachmentUpload');
    $app.formvalidator({}, 'brandForm');

    $('#pricture-grid').on('a.mix-link[data-hook="remove-pic"]', 'click', function (e) {
        e.preventDefault();
        var $this = $(this);
        $this.closest('div.mix').remove();
        return false;
    });

    return {};
});